package org.zf.database.consts;

import cn.hutool.core.bean.BeanException;
import cn.hutool.core.util.EnumUtil;
import lombok.Getter;

import java.util.LinkedHashMap;

/**
 * 映射字段类型
 */
@Getter
public enum FieldType
{
    INT("INT", "整数"),
    NUMBER("NUMBER", "小数"),
    BOOLEAN("BOOLEAN", "0/1"),
    VARCHAR("VARCHAR", "字符串"),
    DATE("DATE", "日期"),
    TIMESTAMP("TIMESTAMP", "时间戳"),
    CLOB("CLOB", "超长文本"),
    BLOB("BLOB", "二进制大对象");

    private final String type;
    private final String name;

    FieldType(String type, String name)
    {
        this.type = type;
        this.name = name;
    }

    public static FieldType parseType(String fieldType) throws RuntimeException
    {
        LinkedHashMap<String, FieldType> enumMap = EnumUtil.getEnumMap(FieldType.class);
        for (FieldType value : enumMap.values())
        {
            if (value.getType().equalsIgnoreCase(fieldType))
                return value;
        }
        throw new BeanException("不支持的数据类型：" + fieldType);
    }
}
